/**
 * Created By xiyuan
 * Author server@xiyuan.name (惜缘叛逆)
 * DateTime 2020/9/1 11:16 AM
 * Describe javascript功能描述
 * MIT License http://www.opensource.org/licenses/mit-license.php
 */


// 主要作用让node脚本中支持 ES6 import/export语法
// npm install babel-register babel-preset-env -D
require('babel-register')({
	"plugins": [
		"transform-es2015-modules-commonjs"
	]
});

// 引入docx生成
const {docxGen} = require('./lib/docxGen');
// 文件逐行读取
const {readLine} = require('./lib/readline');
// 引入目录遍历
const {fileIteration} = require('./lib/fileIteration');

// 'docx文档输出文件
const outDocxFilePath = "./out.docx"
// 代码目录
const codePathDir = "/Users/xiyuan/webServer/wwwroot/project.com/dominos-mobile/src";

// 文档流
const docxGenStream = docxGen();
// 文件计数
let fileCount = 0;

// 给文档添加内容
docxGenStream.add("前30页", {font_size: 20, align: "center", color: '00ffff', back: '000088'});

// 代码目录遍历
fileIteration(
	codePathDir,
	function (pathDir, next) {
		let lineNum = 0;
		
		// 给代码添加页码
		docxGenStream.add("当前第" + (fileCount + 1) + "页代码", {
			font_size: 12,
			align: "left",
			color: '00ffff',
			back: '000088'
		});
		// 文件逐行读取
		readLine(pathDir, function (lineData, stop) {
			docxGenStream.add(lineData);
			// 超过60行停止
			if (++lineNum == 60) {
				stop();
			}
		}, function () {
			++fileCount;
			next(fileCount !== 60);
			if (fileCount === 30) {
				docxGenStream.add("后30页", {font_size: 20, align: "center", color: '00ffff', back: '000088'});
			}
		})
	},
	function (errMsg, errCode) {
		console.log(errMsg, errCode)
		docxGenStream.generate();
	},
	['.vue', function (filepath, extname) {
		return extname == '.js'
	}]
)
// docxGen();

